<?php
class Metersubtype_model extends CI_Model {
	
	private $tbl_data= 'MST_METER_SUBTYPE';
	public function __construct()
	{
		parent::__construct();
	}
	
	function list_all(){
		//$this->db->order_by('id','asc');
		return "SELECT A.STCODE,A.SUBTYPE,B.TYPE FROM MST_METER_SUBTYPE  A INNER JOIN MST_METER_TYPE B ON A.MTCODE=B.MTCODE";
	}
	
	function get_all(){
		return $this->db->get($this->tbl_data)->result_array();;
	}
	
	function count_all(){
		return $this->db->count_all($this->tbl_data);
	}
	function get_by_meter_type($mtcode){
		$this->db->where('MTCODE', $mtcode);
		return $this->db->get($this->tbl_data)->result_array();
	 
	}
	function get_by_id($id){
		$this->db->where('STCODE', $id);
		return $this->db->get($this->tbl_data)->row();
	 
	}
	function save($item){		
		$this->db->insert($this->tbl_data, $item);		
		return $this->db->insert_id();		
	}
	
	function update($item,$id){
		$this->db->where('STCODE', $id);
		$this->db->update($this->tbl_data, $item);
	}
	
	function delete($id){
		$this->db->where('STCODE', $id);
		$this->db->delete($this->tbl_data);
	}
	
 
}
?>